package logic

import (
	"context"
	"month2/C/rpc_C/order"

	"month2/C/api_C/internal/svc"
	"month2/C/api_C/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodsInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsInfoLogic {
	return &GoodsInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodsInfoLogic) GoodsInfo(req *types.GoodsInfoRequest) (resp *types.Response, err error) {
	info, err := l.svcCtx.CRpc.GoodsInfo(l.ctx, &order.GoodsInfoRequest{GoodsId: int64(req.GoodsId)})
	if err != nil {
		return &types.Response{
			Msg:  "商品详情展示失败",
			Data: nil,
			Code: 500,
		}, nil
	}
	return &types.Response{
		Msg:  "商品详情展示成功",
		Data: info,
		Code: 200,
	}, nil
}
